<template>
    <div class="record">

        <div id="list" v-if="data.length > 0">
            <cube-scroll ref="scroll" :options="scroll_options" @pulling-up="upLoad">

                <dl v-for="item in data" :key="item.time" :class="item.type">
                    <dt>
                        <span v-if="item.type ==='add'">+</span>
                        <span v-else>-</span>{{item.balance}} {{setting.currency_name}}
                    </dt>
                    <dd class="source">
                        <span v-if="item.type === 'add'">
                            <template v-if="!plugin.auto.open">签到</template>
                            <template v-else>粉丝奖励</template>
                        </span>
                        <span v-else>
                            <template v-if="!plugin.auto.open">漏签</template>
                            <template v-else>普通用户扣除</template>
                        </span>
                    </dd>
                    <dd class="time">{{item.time}}</dd>
                </dl>

            </cube-scroll>
        </div>
        <empty v-else>暂无数据</empty>

    </div>
</template>

<script>
    import { mapState } from "vuex";
    import empty from "../../../../components/empty/Empty";
    import plugin from "../../../../util/plugin";
    import pluginAuto from "../../../../plugins/auto/index";
    export default {
        name: "record",
        data(){
          return {
              data:[],
              limit:[0,20],
              //滚动参数
              scroll_options:{
                  pullUpLoad: {
                      txt: {
                          more: "上拉加载更多",
                          noMore: "----我也是有底线的----"
                      }
                  }
              },
              //插件信息
              plugin:{
                  // 粉丝自动赠送积分插件
                  auto:{
                      open: false
                  }
              }
          }
        },
        components:{
            empty
        },
        computed:{
            ...mapState({
                setting:"setting"
            })
        },
        created() {
            plugin.tryRun("auto")
                .then((res)=>{
                    this.plugin.auto.open = res;
                    if(res){
                        this.pluginAutoGetList();
                    }else{
                        this.getList();
                    }
                })
        },
        methods:{
            /**
             * 获取列表
             */
            getList(){
                this.$url("signIn/getSignRecord",{
                    uid:this.$sysinfo.uid,
                    limit:this.limit
                })
                .then((res)=>{
                    if(res.data.status === "success"){
                        this.limit[0] += this.limit[1];
                        if(this.$refs.scroll){
                            this.$refs.scroll.forceUpdate(true,true);
                            this.$refs.scroll.refresh();
                        }
                        this.data.push(...res.data.data);
                    }else{
                        if(this.$refs.scroll) this.$refs.scroll.forceUpdate(false,false);
                    }
                });
            },
            /**
             * louie-plugin
             * 粉丝关注自动赠送积分插件，积分变动列表
             */
            pluginAutoGetList(){
                pluginAuto.getRecordList(this.$sysinfo.uid,this.limit,plugin.api)
                .then((res)=>{
                    if(res.data.status === "success"){
                        this.limit[0] += this.limit[1];
                        if(this.$refs.scroll){
                            this.$refs.scroll.forceUpdate(true,true);
                            this.$refs.scroll.refresh();
                        }
                        this.data.push(...res.data.data);
                    }else{
                        if(this.$refs.scroll) this.$refs.scroll.forceUpdate(false,false);
                    }
                });
            },
            //上拉加载
            upLoad(){
                if(this.plugin.auto.open){
                    this.pluginAutoGetList();
                }else{
                    this.getList();
                }
            }
        }
    }
</script>

<style scoped lang="less" src="./record.less"></style>
